/*     */ package com.zimbra.qa.unittest.server;
/*     */ 
/*     */ import com.zimbra.client.ZFolder;
/*     */ import com.zimbra.client.ZImapDataSource;
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.datasource.DataSourceManager;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.ScheduledTask;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import com.zimbra.soap.type.DataSource.ConnectionType;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestDataSourceServer
/*     */   extends TestCase
/*     */ {
/*     */   private static final String USER_NAME = "user1";
/*     */   private static final String TEST_USER_NAME = "testdatasource";
/*  39 */   private static final String NAME_PREFIX = TestDataSourceServer.class.getSimpleName();
/*     */   
/*     */   private String mOriginalAccountPollingInterval;
/*     */   private String mOriginalAccountPop3PollingInterval;
/*     */   private String mOriginalAccountImapPollingInterval;
/*     */   private String mOriginalCosPollingInterval;
/*     */   private String mOriginalCosPop3PollingInterval;
/*     */   private String mOriginalCosImapPollingInterval;
/*     */   
/*     */   public void setUp()
/*     */     throws Exception
/*     */   {
/*  51 */     cleanUp();
/*     */     
/*     */ 
/*  54 */     Account account = TestUtil.getAccount("user1");
/*  55 */     Cos cos = account.getCOS();
/*  56 */     this.mOriginalAccountPollingInterval = account.getAttr("zimbraDataSourcePollingInterval", false);
/*  57 */     if (this.mOriginalAccountPollingInterval == null) {
/*  58 */       this.mOriginalAccountPollingInterval = "";
/*     */     }
/*  60 */     this.mOriginalAccountPop3PollingInterval = account.getAttr("zimbraDataSourcePop3PollingInterval", false);
/*  61 */     if (this.mOriginalAccountPop3PollingInterval == null) {
/*  62 */       this.mOriginalAccountPop3PollingInterval = "";
/*     */     }
/*  64 */     this.mOriginalAccountImapPollingInterval = account.getAttr("zimbraDataSourceImapPollingInterval", false);
/*  65 */     if (this.mOriginalAccountImapPollingInterval == null) {
/*  66 */       this.mOriginalAccountImapPollingInterval = "";
/*     */     }
/*     */     
/*  69 */     this.mOriginalCosPollingInterval = cos.getAttr("zimbraDataSourcePollingInterval", "");
/*  70 */     this.mOriginalCosPop3PollingInterval = cos.getAttr("zimbraDataSourcePop3PollingInterval", "");
/*  71 */     this.mOriginalCosImapPollingInterval = cos.getAttr("zimbraDataSourceImapPollingInterval", "");
/*     */   }
/*     */   
/*     */   public void testScheduling()
/*     */     throws Exception
/*     */   {
/*  77 */     ZMailbox zmbox = TestUtil.getZMailbox("user1");
/*  78 */     ZFolder folder = TestUtil.createFolder(zmbox, "/" + NAME_PREFIX + "-testScheduling");
/*  79 */     Provisioning prov = Provisioning.getInstance();
/*  80 */     Server server = prov.getLocalServer();
/*  81 */     int port = server.getImapBindPort();
/*  82 */     ZImapDataSource zds = new ZImapDataSource(NAME_PREFIX + " testScheduling", true, "localhost", port, "user2", "test123", folder.getId(), DataSource.ConnectionType.cleartext);
/*     */     
/*  84 */     String dsId = zmbox.createDataSource(zds);
/*     */     
/*     */ 
/*  87 */     Mailbox mbox = TestUtil.getMailbox("user1");
/*  88 */     String attrName = "zimbraDataSourcePollingInterval";
/*  89 */     String imapAttrName = "zimbraDataSourceImapPollingInterval";
/*  90 */     TestUtil.setDataSourceAttr("user1", zds.getName(), attrName, "0");
/*  91 */     checkSchedule(mbox, dsId, null);
/*     */     
/*  93 */     TestUtil.setDataSourceAttr("user1", zds.getName(), attrName, "10m");
/*  94 */     checkSchedule(mbox, dsId, Integer.valueOf(600000));
/*     */     
/*  96 */     TestUtil.setAccountAttr("user1", imapAttrName, "");
/*  97 */     TestUtil.setDataSourceAttr("user1", zds.getName(), attrName, "");
/*  98 */     checkSchedule(mbox, dsId, null);
/*     */     
/* 100 */     TestUtil.setAccountAttr("user1", imapAttrName, "5m");
/* 101 */     checkSchedule(mbox, dsId, Integer.valueOf(300000));
/*     */     
/* 103 */     TestUtil.setDataSourceAttr("user1", zds.getName(), attrName, "0");
/* 104 */     checkSchedule(mbox, dsId, null);
/*     */     
/*     */ 
/*     */ 
/* 108 */     TestUtil.setDataSourceAttr("user1", zds.getName(), attrName, "");
/* 109 */     checkSchedule(mbox, dsId, Integer.valueOf(300000));
/*     */     
/* 111 */     TestUtil.setDataSourceAttr("user1", zds.getName(), "zimbraDataSourceEnabled", "FALSE");
/* 112 */     checkSchedule(mbox, dsId, null);
/*     */   }
/*     */   
/*     */   private void checkSchedule(Mailbox mbox, String dataSourceId, Integer intervalMillis) throws Exception
/*     */   {
/* 117 */     ScheduledTask task = DataSourceManager.getTask(mbox, dataSourceId);
/* 118 */     if (intervalMillis == null) {
/* 119 */       assertNull(task);
/*     */     } else {
/* 121 */       assertEquals(intervalMillis.longValue(), task.getIntervalMillis());
/*     */     }
/*     */   }
/*     */   
/*     */   public void tearDown()
/*     */     throws Exception
/*     */   {
/* 128 */     Account account = TestUtil.getAccount("user1");
/* 129 */     Cos cos = account.getCOS();
/*     */     
/* 131 */     account.setDataSourcePollingInterval(this.mOriginalAccountPollingInterval);
/* 132 */     account.setDataSourcePop3PollingInterval(this.mOriginalAccountPop3PollingInterval);
/* 133 */     account.setDataSourceImapPollingInterval(this.mOriginalAccountImapPollingInterval);
/*     */     
/* 135 */     cos.setDataSourcePollingInterval(this.mOriginalCosPollingInterval);
/* 136 */     cos.setDataSourcePop3PollingInterval(this.mOriginalCosPop3PollingInterval);
/* 137 */     cos.setDataSourceImapPollingInterval(this.mOriginalCosImapPollingInterval);
/*     */     
/* 139 */     cleanUp();
/*     */   }
/*     */   
/*     */   public void cleanUp() throws Exception
/*     */   {
/* 144 */     TestUtil.deleteAccount("testdatasource");
/* 145 */     TestUtil.deleteTestData("user1", NAME_PREFIX);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/server/TestDataSourceServer.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */